﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Kaskelot.Web.Services;
using Stockholm.SOA.Kaskelot.WCF.DataContracts;

namespace Kaskelot.Web.UserControls.FormControls
{
    public partial class Enkelval : FormControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (WebService svc = new WebService())
            {
                if (Falt != null)
                {
                    FaltAlternativ[] alternativ = svc.GetFaltAlternativForFalt(Falt.Id).OrderBy(fa => fa.Namn).ToArray();

                    if (alternativ.Length <= 3)
                    {
                        rpFewChoices.DataSource = alternativ;
                        rpFewChoices.DataBind();
                        pnFewChoices.Visible = true;
                    }
                    else
                    {
                        rpManyChoices.DataSource = alternativ;
                        rpManyChoices.DataBind();
                        pnManyChoices.Visible = true;
                    }
                }
            }
        }

        protected string Selected(object obj)
        {
            string result = "";

            FaltAlternativ item = obj as FaltAlternativ;

            if (Falt.Default != null)
            {
                if (item.Namn.ToLower().Equals(Falt.Default.ToLower()))
                    result = "selected=\"selected\"";
            }

            return result;
        }

        protected string Checked(object obj)
        {
                        string result = "";

            FaltAlternativ item = obj as FaltAlternativ;

            if (Falt.Default != null)
            {
                if (item.Namn.ToLower().Equals(Falt.Default.ToLower()))
                    result = "checked=\"checked\"";
            }

            return result;
        }

    }
}